package com.yer.note.utils;

import static android.content.Context.MODE_PRIVATE;
import static android.content.Context.NOTIFICATION_SERVICE;


import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;

import android.view.View;
import android.widget.Toast;


import androidx.core.app.NotificationCompat;


import com.google.android.material.snackbar.Snackbar;
import com.yer.note.R;
import com.yer.note.entity.Diary;
import com.yer.note.entity.User;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;


/**
 * @Author: HibaraAi
 * @Date: 2021-08-15 07:20
 * @Description:
 */
public class BaseUtils {
    public static  String getCurrentTime(){
        Date day=new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return df.format(day);
    }
    /**
     * 加载实验数据
     */
    public static String randomUUID() {
        UUID uuid = UUID.randomUUID();
        return uuid.toString().replace("-", "").toUpperCase();
    }
    public static void newUser(){
        User user = new User("cwt","123456","hello",randomUUID());
        user.save();
    }
    public static void reloadData(){
        List<String> uuids = new ArrayList<>();
        for(int i = 0;i<12;i++){
            uuids.add(randomUUID());
        }
        String useruuid = User.findById(User.class,1).getMyuuid();
        Diary diary2 = new Diary("I am 2 context","晴","#生活#","桂林电子科技大学","2022-9-2 3:12:00", uuids.get(1),useruuid);
        Diary diary3 = new Diary("I am 3 context","晴","#生活#","桂林电子科技大学","2022-9-2 3:12:01",uuids.get(2),useruuid);
        Diary diary4 = new Diary("I am 4 context","晴","#生活#","桂林电子科技大学","2022-9-2 3:12:02",uuids.get(3),useruuid);
        Diary diary5 = new Diary("I am 5 context","晴","#学习#","桂林电子科技大学","2022-9-2 3:12:03",uuids.get(4),useruuid);
        Diary diary6 = new Diary("I am 6 context","晴","#学习#","桂林电子科技大学","2022-9-2 3:12:04",uuids.get(5),useruuid);
        Diary diary7 = new Diary("I am 7 context","晴","#游戏#","桂林电子科技大学","2022-9-2 3:12:05",uuids.get(6),useruuid);
        Diary diary8 = new Diary("I am 8 context","晴","#冥想#","桂林电子科技大学","2022-9-2 3:12:06",uuids.get(7),useruuid);
        Diary diary9 = new Diary("I am 8 context","晴","#ssdjh#","桂林电子科技大学","2022-9-2 3:12:07",uuids.get(8),useruuid);
        Diary diary10 = new Diary("I am 8 context","晴","#jfsdh#","桂林电子科技大学","2022-9-2 3:12:08",uuids.get(9),useruuid);
        Diary diary11 = new Diary("I am 8 context","晴","#ssdhf#","桂林电子科技大学","2022-9-2 3:12:09",uuids.get(10),useruuid);
        Diary diary12 = new Diary("I am 8 context","晴","#冥想#","桂林电子科技大学","2022-9-2 3:12:10",uuids.get(11),useruuid);
        diary2.save();
        diary3.save();
        diary4.save();
        diary5.save();
        diary6.save();
        diary7.save();
        diary8.save();
        diary9.save();
        diary10.save();
        diary11.save();
        diary12.save();
    }

    /**
     * 短时间的Coast提示
     *
     * @param context context
     * @param tip     提示内容
     */
    public static void shortTipInCoast(Context context, String tip) {
        Toast.makeText(context, tip, Toast.LENGTH_SHORT).show();
    }

    /**
     * 长时间的Coast提示
     *
     * @param context context
     * @param tip     提示内容
     */
    public static void longTipInCoast(Context context, String tip) {
        Toast.makeText(context, tip, Toast.LENGTH_LONG).show();
    }

    /**
     * 弹窗提示
     *
     * @param context context
     * @param title   标题
     * @param content 提示内容
     */
    public static void alertDialogToShow(Context context, String title, String content) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(title);
        builder.setMessage(content);
        builder.setPositiveButton("OK", null);
        builder.show();
    }

    /**
     * 单纯的Activity跳转
     *
     * @param context context
     * @param clazz   跳转目标Activity的Class
     */
    public static void gotoActivity(Activity context, Class clazz) {
        Intent intent = new Intent(context, clazz);
        context.startActivity(intent);
    }


    /**
     * 将内容复制到系统剪贴板
     * @param context context
     * @param content 需要复制的内容
     * @return true-复制成功
     */
    public static Boolean copyInClipboard(Context context, String content) {
        try {
            //获取剪贴板管理器：
            ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
            // 创建普通字符型ClipData
            ClipData mClipData = ClipData.newPlainText("Label", content);
            // 将ClipData内容放到系统剪贴板里。
            cm.setPrimaryClip(mClipData);
            return true;
        } catch (Exception e) {
            return false;
        }
    }


    /**
     * 长时间的Snack提示
     *
     * @param view
     * @param tip
     */
    public static void longTipInSnack(View view, String tip) {
        Snackbar.make(view, tip, Snackbar.LENGTH_LONG).show();
    }

    /**
     * 短时间的Snack提示
     *
     * @param view
     * @param tip
     */
    public static void shortTipInSnack(View view, String tip) {
        Snackbar.make(view, tip, Snackbar.LENGTH_SHORT).show();
    }

    /**
     * 简单的系统任务栏通知
     * 只能显示一行字，没有点击操作
     *
     * @param context
     * @param notice
     */
    public static void simpleSysNotice(Context context, String notice) {
        String channelId = "ChannelId"; // 通知渠道
        Notification notification = new Notification.Builder(context, channelId)
                .setChannelId(channelId)
                .setAutoCancel(true)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentText(notice)
                .build();
        // 2. 获取系统的通知管理器(必须设置channelId)
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(NOTIFICATION_SERVICE);
        NotificationChannel channel = new NotificationChannel(
                channelId,
                "消消乐提示",
                NotificationManager.IMPORTANCE_LOW);
        notificationManager.createNotificationChannel(channel);
        // 3. 发送通知(Notification与NotificationManager的channelId必须对应)
        notificationManager.notify(1, notification);
    }


    public static void longTextSysNotice(Context context, String notice) {
        NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        NotificationChannel channel = new NotificationChannel(
                "channelId",
                "消消乐提示",
                NotificationManager.IMPORTANCE_LOW);
        manager.createNotificationChannel(channel);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "channelId")
                .setContentText("回到通知栏上也是一样，每个开发者都只想着尽可能地去宣传自己的App，最后用户的手机就乱得跟鸡窝一样了。但")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setAutoCancel(true);
        //创建大文本样式
        NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
        bigTextStyle.bigText(notice);
        builder.setStyle(bigTextStyle); //设置大文本样式
        Notification notification = builder.build();
        manager.notify(1, notification);
    }
}
